package org.jetnuke.dao.generic;

import java.sql.PreparedStatement;
import java.sql.ResultSet;

import net.jforum.JForumExecutionContext;
import net.jforum.util.preferences.SystemGlobals;

import org.jetnuke.entities.BlogSettings;

public class GenericBlogSettingsDAO implements org.jetnuke.dao.BlogSettingsDAO {

	public BlogSettings get() throws Exception {
		PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("BlogSettingsModel.get"));
		
		ResultSet rs = p.executeQuery();
		BlogSettings s = new BlogSettings();
		
		rs.next();
		fillBlogSettingsFromResultSet(s, rs);
		
		rs.close();
		p.close();

		return s;
	}

	protected void fillBlogSettingsFromResultSet(BlogSettings s, ResultSet rs) throws Exception{
		s.setLICENSE(rs.getString("BLOG_LICENSE_ACCEPT"));
		s.setLIMIT(rs.getInt("SIZE_LIMIT_KB"));
		
	}

	public void update(BlogSettings bs) throws Exception {
		PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("BlogSettingsModel.update"));
		p.setString(1,bs.getLICENSE());
		p.setInt(2,bs.getLIMIT());
		p.executeUpdate();
		p.close();

	}

}
